<html>
<head><meta charset="utf-8"><title>Named Labels Lint · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html">Named Labels Lint</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246413610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/246413610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> asquared31415 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#246413610">(Jul 19 2021 at 03:49)</a>:</h4>
<p>I'm having issues implementing the lint to detect and warn against the usage of named labels, specifically with regards to getting the right span for error reporting.  The ability to use <code>\n</code> in a string or raw strings complicates things a lot since I need to work with the parsed string to look for characters (particularly newlines), but the error reporting needs to use a span from the source string.</p>
<p>The approach taken by the lints for the syntax directives won't work because I need to search for a pattern of characters, not a specific string, and also for the aformentioned escape characters reason.</p>
<p>If anyone has any tips as to how to implement this, please help.</p>



<a name="246423075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/246423075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#246423075">(Jul 19 2021 at 07:16)</a>:</h4>
<p>My recommendation would be: don't bother. Accurately translating spans for string literals is just too difficult.</p>



<a name="246423134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/246423134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#246423134">(Jul 19 2021 at 07:16)</a>:</h4>
<p>Just naming the label in the lint message should be enough.</p>



<a name="246423290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/246423290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#246423290">(Jul 19 2021 at 07:18)</a>:</h4>
<p>Alternatively you could try to do the same as the syntax directives and just use <code>find_span</code> after you find a specific instance of a named label.</p>



<a name="246424201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/246424201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#246424201">(Jul 19 2021 at 07:30)</a>:</h4>
<p>So basically:</p>
<ol>
<li>Search for labels in the asm template string.</li>
<li>Eliminate duplicates, only match each label once.</li>
<li>Call <code>find_span</code> for each unique label found.</li>
<li>If find_span fails for one label, ignore it. If find_span fails for all labels, return the span of the entire template string.</li>
</ol>



<a name="247259047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/247259047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> asquared31415 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#247259047">(Jul 26 2021 at 20:43)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span>  You left some feedback about changing the wording on the lint.  However I think that we have different expectations about what this lint should do.  In my opinion that changed wording of "avoid using" and "should" is a lot weaker of a suggestion, what is the reasoning behind that?  In my opinion, there is no way to use named labels correctly, as the RFC says, and so the wording should reflect that.  I would like to hear why you think it should be changed though.</p>



<a name="247644723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/247644723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#247644723">(Jul 29 2021 at 21:37)</a>:</h4>
<p><span class="user-mention" data-user-id="384759">@asquared31415</span> Sorry, I missed your message. The main reason why I suggested changing the wording is to be consistent with other lints. A lint is still fundamentally a suggestion which can be ignored, otherwise we would have made this a hard error instead of a lint.</p>



<a name="247644896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/247644896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#247644896">(Jul 29 2021 at 21:39)</a>:</h4>
<p>I can think of some edge cases where it may be useful to have named labels, such as naked functions. In the end if the user chooses to ignore the warning then it is their fault if things break.</p>



<a name="247651350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Named%20Labels%20Lint/near/247651350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> asquared31415 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Named.20Labels.20Lint.html#247651350">(Jul 29 2021 at 22:53)</a>:</h4>
<p>That makes sense I suppose.  Thanks.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>